<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class AppParser extends CI_Parser {

    function module_parse($template, $data, $return = FALSE){
        $CI =& get_instance();

        $template = $CI->load->module_view($template, $data, TRUE);
        if ($template == ''){
            return FALSE;
        }

        $this->_execute_parse($template, $data, $return);

        return $template;
    }
    
    function parse_layout($template, $data, $return = FALSE){
        $CI =& get_instance();
        $template = $CI->load->layout($template, $data, TRUE);
        
        if ($template == ''){
            return FALSE;
        }

        $this->_execute_parse($template, $data, $return);
        return $template;
    }
    
    function _execute_parse(&$template, &$data, $return){
        $CI =& get_instance();
        foreach ($data as $key => $val){
            if (is_array($val)){
                $template = $this->_parse_pair($key, $val, $template);        
            }else{
                @$template = $this->_parse_single($key, (string)$val, $template);
            }
        }
        
        if ($return == FALSE){
            $CI->output->append_output($template);
        }
    }
}